# 作业1：将li列表中的大于5的数字%2取余放入一个生成器中
li = [11, 21, 4, 55, 6, 67, 123, 54, 66, 9, 90, 56, 34, 22]
# 方法1
gen = (i % 2 for i in li if i > 5)
print(next(gen))


# 方法2
def func1():
    for i in li:
        if i > 5:
            yield i % 2


# 作业2  通过send()拼接一个url地址
def func2():
    url = None
    for i in range(6):
        s = yield url
        url = f"http://{s}/user/login"


res = func2()
next(res)
print(res.send("172.23.26.9"))


# 作业3：统计列表arry中比x大的数并去重，统计arry中比x小的偶数

# 方法一
def func3(arry, x):
    li = []
    li2 = []
    for i in arry:
        if i > x and i not in li:
            li.append(i)
    for i in arry:
        if i < x and i % 2 == 0:
            li2.append(i)
    yield len(li), li2

print("----------")
res = func3([1, 2, 3, 4, 5, 6], 4)
print(next(res))


# 方法2
def func4(arry, x):
    count = len([i for i in set(arry) if i > x]) # set可以去重统计，li.count(2)可以统计元素个数
    li = [i for i in arry if i < x and i % 2 == 0]
    yield count, li


res2 = func4([1, 2, 3, 4, 5, 6], 4)
print(next(res2))

print(list(zip((1,2,3),(1,2,3))))
print(dict(zip((1,2,3),(1,2,3))))
print(set(zip((1,2,3),(1,2,3))))